﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Drawing;

namespace coliseu.Classes
{
    class Utils
    {
        public static byte[] imageToByteArray(System.Drawing.Image imageIn,string tipo)
        {
            MemoryStream ms = new MemoryStream();

            if(tipo == "gif")
                imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);

            if(tipo == "png")
                imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

            if (tipo == "jpg")
                imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

            if (tipo == "bmp")
                imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);

            return ms.ToArray();
        }

        public static Image byteArrayToImage(byte[] byteArrayIn)
        {
            MemoryStream ms = new MemoryStream(byteArrayIn);
            Image returnImage = Image.FromStream(ms);
            return returnImage;
        }
       
    }
}
